Straight from the dxl Reference manual (page 19):
// Overload print to define an Object printer
void print(Object o) {
string h = o."Object Heading"
string t = o."Object Text"
print h ":\n\n" t "\n"
}
print current Object
bool bWriteToStream = true
Stream object_output = write "d:\\DOORS\\dxl output\\metrics.txt"
void print(string s) {
bWriteToStream ? object_output << s "\n" : print s "\n"
}
print "Goes to DXL output stream as expected"
close object_output
bWriteToStream ? print s "\n" : object_output << s "\n"
dedawson - Mon Mar 12 17:28:35 EDT 2012 |
Re: Difficulty understanding dxl function overloading You should first overload the original print routine. In your script, DXL gets confused, because you first overload void print(string s) but then in the routine body you are using the original print routine in bWriteToStream ? object_output << s "\n" : print s "\n"
.
void print_orig(string s){print s}
bool bWriteToStream = true
Stream object_output = write "d:\\DOORS\\dxl output\\metrics.txt"
void print(string s) {
bWriteToStream ? object_output << s "\n" : print_orig(s) "\n"
}
print "Goes to DXL output stream as expected"
close object_output
|
Re: Difficulty understanding dxl function overloading Peter_Albert - Tue Mar 13 03:54:08 EDT 2012 You should first overload the original print routine. In your script, DXL gets confused, because you first overload void print(string s) but then in the routine body you are using the original print routine in bWriteToStream ? object_output << s "\n" : print s "\n"
.
void print_orig(string s){print s}
bool bWriteToStream = true
Stream object_output = write "d:\\DOORS\\dxl output\\metrics.txt"
void print(string s) {
bWriteToStream ? object_output << s "\n" : print_orig(s) "\n"
}
print "Goes to DXL output stream as expected"
close object_output
Thanks Peter. What you suggested worked, but I was still puzzled as to why the example in the DXL manual failed, since I followed it exactly, merely substituting string for Object. The overload in the manual modified the definition of print, yet still called print within it's body.
Module m = current
Object o = current
bool bWriteToStream = true
Stream output_stream = write "d:\\DOORS\\dxl output\\overload_test.txt"
void print_orig(string s){print s}
void print(string s) {bWriteToStream ? output_stream << s "\n" : print_orig s "\n"}
void print(Object o) {
string h = o."Object Heading"
string t = o."Object Text"
print h ":\n\n" t "\nto output stream\n"
}
print current Object
print "This goes to the output stream"
bWriteToStream = false
print "And this goes to the output pane"
close output_stream
|